package com.liqw.activiti.controller;

import com.liqw.activiti.service.TaskService;
import com.liqw.activiti.service.ProcessService;
import lombok.AllArgsConstructor;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@RestController
@RequestMapping("/process")
public class ProcessController {
    private final ProcessService processService;

    private final TaskService taskService;

    /**
     * 注册流程
     *
     * @return
     */
    @RequestMapping("/deploy")
    public Deployment deploy() {
        return processService.deploy("simple.bpmn");
    }

    /**
     * 启动
     *
     * @param processDefinitionKey
     * @return
     */
    @RequestMapping("/start")
    public ProcessInstance start(String processDefinitionKey) {
        return processService.start(processDefinitionKey);
    }

    /**
     * 提交
     *
     * @param taskId
     * @return
     */
    @RequestMapping("/submit")
    public boolean submit(String taskId) {
        return taskService.submit(taskId);
    }

    /**
     * 驳回
     */
    @RequestMapping("/reject")
    public boolean reject(String taskId){
        return taskService.reject(taskId);
    }

    /**
     * 取消
     *
     * @param taskId
     * @return
     */
    @RequestMapping("/cancel")
    public boolean cancel(String taskId) {
        return taskService.cancel(taskId);
    }

    /**
     * 转办
     */
    @RequestMapping("/transfer")
    public boolean transfer(String taskId){
        return taskService.transfer(taskId);
    }

    /**
     * 挂起
     */
    @RequestMapping("/pending")
    public boolean pending(String taskId){
        return taskService.pending(taskId);
    }

    /**
     * 根据流程id直接结束流程
     *
     * @return
     * @paramru
     */
    @RequestMapping("/stop")
    public boolean stop(String processId) {
        return processService.stop(processId);
    }
}
